#include <linux/smp.h>
#include <linux/percpu.h>

#include <riscv/smp.h>

extern unsigned long boot_cpu_hartid;

enum ipi_message_type
{
    IPI_RESCHEDULE,
    IPI_CALL_FUNC,
    IPI_CPU_STOP,
    IPI_CPU_CRASH_STOP,
    IPI_IRQ_WORK,
    IPI_TIMER,
    IPI_CPU_BACKTRACE,
    IPI_KGDB_ROUNDUP,

    IPI_MAX
};

static unsigned int __cpuid_to_hartid_map[NR_CPUS] = {
    [0 ... NR_CPUS - 1] = INVALID_HARTID,
};

void hartid_to_cpuid_map(unsigned int hartid, unsigned int cpu)
{
    __cpuid_to_hartid_map[cpu] = hartid;
}

unsigned long cpuid_to_hartid_map(unsigned int cpu)
{
    return __cpuid_to_hartid_map[cpu];
}

void smp_setup_processor_id(void)
{
    hartid_to_cpuid_map(boot_cpu_hartid, 0);
}

unsigned raw_smp_processor_id(void)
{
    unsigned long hartid;

    __asm__ volatile("csrr %0, mhartid" : "=r"(hartid));

    return current->cpu;
}
